export function createSocket(onMessage, onError) {
    // 创建WebSocket服务器并监听指定端口
    const socket = new WebSocket('ws://localhost:8266/rfid');
    // 监听连接建立事件
    socket.addEventListener('open', (event) => {
        console.log('WebSocket连接已建立');
    });

    // 监听消息接收事件
    socket.addEventListener('message', (event) => {
        if (onMessage) {
            onMessage(event.data);
        }
    });

    // 监听消息接收事件
    socket.addEventListener('error', (event) => {
        onError(event);
    });

    socket.addEventListener('close', () => {
        console.log('WebSocket连接已关闭');
    })
    return socket;

}